/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package datos;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Ing. Monica Merlo, Ing. Agustin  Fernandez
 */
@Entity
@Table(name = "contrato")
@NamedQueries({
@NamedQuery(name = "Contrato.encontrarContratoPorEmpresa", query = "SELECT c FROM Contrato c WHERE c.idEmpresaContratista.id = :idEmpresaContratista AND c.idObra.id = :idObra AND c.idObra.eliminada = 0 ORDER BY c.idObra.nombre"),
@NamedQuery(name = "Contrato.findAll", query = "SELECT c FROM Contrato c"),
@NamedQuery(name = "Contrato.findById", query = "SELECT c FROM Contrato c WHERE c.id = :id"),
@NamedQuery(name = "Contrato.findByFecha", query = "SELECT c FROM Contrato c WHERE c.fecha = :fecha"),
@NamedQuery(name = "Contrato.findByPlazo", query = "SELECT c FROM Contrato c WHERE c.plazo = :plazo"),
@NamedQuery(name = "Contrato.findByTipoPlazo", query = "SELECT c FROM Contrato c WHERE c.tipoPlazo = :tipoPlazo")})
public class Contrato implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecha;
    @Basic(optional = false)
    @Lob
    @Column(name = "titulo")
    private String titulo;
    @Lob
    @Column(name = "observaciones")
    private String observaciones;
    @Column(name = "plazo")
    private String plazo;
    @Column(name = "tipoPlazo")
    private String tipoPlazo;
    @JoinColumn(name = "idEmpresaContratista", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EmpresaContratista idEmpresaContratista;
    @JoinColumn(name = "idObra", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Obra idObra;
    @JoinColumn(name = "idPeriodoCertificacion", referencedColumnName = "id")
    @ManyToOne
    private PeriodoCertificacion idPeriodoCertificacion;

    public Contrato() {
    }

    public Contrato(Integer id) {
        this.id = id;
    }

    public Contrato(Integer id, Date fecha, String titulo) {
        this.id = id;
        this.fecha = fecha;
        this.titulo = titulo;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

    public String getObservaciones() {
        return observaciones;
    }

    public void setObservaciones(String observaciones) {
        this.observaciones = observaciones;
    }

    public String getPlazo() {
        return plazo;
    }

    public void setPlazo(String plazo) {
        this.plazo = plazo;
    }

    public String getTipoPlazo() {
        return tipoPlazo;
    }

    public void setTipoPlazo(String tipoPlazo) {
        this.tipoPlazo = tipoPlazo;
    }

    public EmpresaContratista getIdEmpresaContratista() {
        return idEmpresaContratista;
    }

    public void setIdEmpresaContratista(EmpresaContratista idEmpresaContratista) {
        this.idEmpresaContratista = idEmpresaContratista;
    }

    public Obra getIdObra() {
        return idObra;
    }

    public void setIdObra(Obra idObra) {
        this.idObra = idObra;
    }

    public PeriodoCertificacion getIdPeriodoCertificacion() {
        return idPeriodoCertificacion;
    }

    public void setIdPeriodoCertificacion(PeriodoCertificacion idPeriodoCertificacion) {
        this.idPeriodoCertificacion = idPeriodoCertificacion;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contrato)) {
            return false;
        }
        Contrato other = (Contrato) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "datos.Contrato[id=" + id + "]";
    }

}
